local common = require "common"
local ClientSession = require "client_session.client_session"

ClientSessionMgr = {}

function ClientSessionMgr:New(o)
    o = o or {}	
	self.__index = self
	setmetatable(o, self)
	
	-- 下面写成员变量
	o.client_session_map_ = {}
	o.client_session_by_pid_map_ = {}
    return o
end

function ClientSessionMgr:AddClient(client_uid, pid)
	local client_session = ClientSession:New()
	self.client_session_map_[client_uid] = client_session
	self.client_session_by_pid_map_[pid] = client_session
	return client_session	
end

function ClientSessionMgr:CleanupClient(client_uid)
	local client_session = self.client_session_map_[client_uid]
	if client_session then
		local pid = client_session:get_pid()
		if self.client_session_by_pid_map_[pid] then
			self.client_session_by_pid_map_[pid] = nil
		end

		self.client_session_map_[client_uid] = nil
	end
end

function ClientSessionMgr:get_client_session_by_uid(client_uid)
	return self.client_session_map_[client_uid]
end

function ClientSessionMgr:get_client_session_by_pid(pid)
	return self.client_session_by_pid_map_[pid]
end

return ClientSessionMgr